import datetime

from App.ext import db
from App.models import BaseModel


class Devices(BaseModel):
    mac = db.Column(db.String(64), unique=True)
    UUID = db.Column(db.String(64))
    major = db.Column(db.String(16))  # , name="楼号"
    minor = db.Column(db.String(16))  # , name="楼层"
    lat = db.Column(db.String(32))  # , name="设备安装的纬度"
    lng = db.Column(db.String(32))  # , name="设备安装的经度"
    time = db.Column(db.DateTime, default=datetime.datetime.now())  # , name="创建创建时间"


# 用户
class User(BaseModel):
    phone = db.Column(db.String(32), unique=True)  # , name="用户唯一标示"


# 用户扫描上传的信息
class Collection(BaseModel):
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    col2user = db.relationship("User", backref="user2col")

    mac = db.Column(db.String(64), unique=True)
    major = db.Column(db.String(16))  # , name="楼号"
    minor = db.Column(db.String(16))  # , name="楼层"
    rssi = db.Column(db.Integer)  # , name="信号强度"
    tx_power = db.Column(db.Integer)  # , name="发射功率"
    time = db.Column(db.DateTime, default=datetime.datetime.now())  # , name="信号采集时间"


# 计算完成后用户的是坐标结果
class CalResult(BaseModel):
    user_id = db.Column(db.Integer, db.ForeignKey("user.id"))
    cal2user = db.relationship("User", backref="user2cal")

    lat = db.Column(db.String(32))  # , name="计算完成后的纬度"
    lng = db.Column(db.String(32))  # , name="计算完成后的经度"
    time = db.Column(db.DateTime, default=datetime.datetime.now())  #


# 测试用户扫描的数据
class ScannerDate(BaseModel):
    mac = db.Column(db.String(64), nullable=True)
    UUID = db.Column(db.String(64), nullable=True)  # , name="设备的UUID"
    major = db.Column(db.Integer, nullable=True)  # , name="楼号"
    minor = db.Column(db.Integer, nullable=True)  # , name="楼层"
    rssi = db.Column(db.Integer, nullable=True)  # , name="信号强度"
    tx_power = db.Column(db.Integer, nullable=True)  # , name="发射功率"
    time = db.Column(db.DateTime, default=datetime.datetime.now())  # , name="信号采集时间"
